package com.wangfei.lessondemo;

import android.support.v4.view.ViewCompat;
import android.support.v4.widget.SlidingPaneLayout;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.LinearLayout;

public class MenuActivity extends AppCompatActivity implements SlidingPaneLayout.PanelSlideListener {

    private SlidingPaneLayout slidingPaneLayout;
    private LinearLayout linearLayout;
    private FrameLayout frame_layout;

//    5.0以上的版本支持 侧滑缩放

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_menu);
        slidingPaneLayout = (SlidingPaneLayout) findViewById(R.id.slidding_layout);
        //菜单的打开关闭
//        slidingPaneLayout.closePane();
//        slidingPaneLayout.openPane();
        //类似的qq滑动的菜单打开的时候，主布局缩小

        slidingPaneLayout.setPanelSlideListener(this);
        //
        linearLayout = (LinearLayout) findViewById(R.id.slidding_meau_2);
        //主控件
        frame_layout = (FrameLayout) findViewById(R.id.frame_layout);
    }

    //滑动中--主界面缩小
    @Override
    public void onPanelSlide(View panel, float slideOffset) {
//   状态区分     完全关闭0  全部打开1

        //静态方法，兼容包  -- 最低兼容
        ViewCompat.setPivotX(frame_layout, 0);
        ViewCompat.setPivotY(frame_layout, frame_layout.getHeight() / 2);
        ViewCompat.setScaleX(frame_layout, 1 - slideOffset * 0.5f);  //宽高等比缩放
        ViewCompat.setScaleY(frame_layout, 1 - slideOffset * 0.5f);
//        移动动画
        ViewCompat.setTranslationX(linearLayout, linearLayout.getWidth() / 2 * (1 - slideOffset));
//  design 出现8个控件

//        //设置锚点坐标--高版本支持写法
//        frame_layout.setPivotX(0);
//        frame_layout.setScaleX(1 - slideOffset * 0.5f);  //宽高等比缩放
//        frame_layout.setScaleY(1 - slideOffset * 0.5f);
    }

    @Override
    public void onPanelOpened(View panel) {

    }

    @Override
    public void onPanelClosed(View panel) {

    }
}
